package cn.javabb.web.config;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

@Component
public class InitialSystem implements ServletContextListener, ApplicationContextAware {

    private static ApplicationContext applicationContext;

    /**
     * 加载初始化数据
     * @param application
     */
    public void loadInitialData(ServletContext application) {
    }

    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        loadInitialData(servletContextEvent.getServletContext());
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {

    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}
